package com.uairobot.bill.yz.office.agent.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.uairobot.bill.yz.office.agent.entity.UploadFile;
import com.uairobot.bill.yz.office.agent.entity.YzPreview;
import com.uairobot.bill.yz.office.agent.repository.UploadFileRepository;
import com.uairobot.bill.yz.office.agent.repository.YzPreviewRepository;

import lombok.extern.slf4j.Slf4j;

/**
 * @author bill robot
 * @date 2020年1月14日_下午2:18:46 
 * @version 1.0 
 * @desc
 */
@Service
@Slf4j
public class YzPreviewService {

  @Autowired
  private YzPreviewRepository ypr;
  @Autowired
  private UploadFileRepository uploadFileRepository;

  public YzPreview getById(String id) {
    log.info("id : " + id);
    YzPreview yzPreview = ypr.findOne(id);
    yzPreview.setBrowseCount(yzPreview.getBrowseCount() + 1);
    ypr.save(yzPreview);

    UploadFile uploadFile = uploadFileRepository.findOne(id);
    yzPreview.setFilename(uploadFile.getFilename());
    yzPreview.setSize(uploadFile.getSize());
    yzPreview.setUploadTime(uploadFile.getUploadTime());
    yzPreview.setUri(uploadFile.getUri());
    return yzPreview;
  }
}
